package com.meilai.project.service.business.customer.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.meilai.project.entity.business.customer.CustomerContact;
import com.meilai.project.mapper.business.customer.CustomerContactMapper;
import com.meilai.project.service.business.customer.CustomerContactService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meilai.project.service.business.dataLevel.DataQueryBusinessLevelService;
import com.meilai.project.util.ThreadLocalUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 客户联系人信息表 服务实现类
 * </p>
 *
 * @author xhy
 * @since 2022-02-21
 */
@Service
public class CustomerContactImpl extends ServiceImpl<CustomerContactMapper, CustomerContact> implements CustomerContactService {

    @Autowired
    private DataQueryBusinessLevelService dataQueryBusinessLevelService;

    @Override
    public List<CustomerContact> queryList(Long id) {
        List<CustomerContact> list = this.list(Wrappers.<CustomerContact>lambdaQuery().eq(CustomerContact::getCustomer_id, id));
        Long user_id = ThreadLocalUserUtil.get().getId();
        int level = dataQueryBusinessLevelService.getUserMaxLevel("customer_contact", user_id);
        return list.stream().filter(item -> item.getLevel_num() <= level).collect(Collectors.toList());
    }
}
